package com.bj58.ecdata.dashboard.controllers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import com.bj58.ecdata.dashboard.constant.ResumeConst;
import com.bj58.ecdata.dashboard.databll.ZhishuZhaopinBLL;
import com.bj58.ecdata.dashboard.utils.MyServletRequestUtils;
import com.bj58.wf.mvc.ActionResult;
import com.bj58.wf.mvc.BeatContext.Model;
import com.bj58.wf.mvc.MvcController;
import com.bj58.wf.mvc.annotation.GET;
import com.bj58.wf.mvc.annotation.POST;
import com.bj58.wf.mvc.annotation.Path;
import com.google.common.collect.Lists;

/**
 * 
 * @author wangchonglu  2015年12月10日 
 *
 */
@Path("/zhishu/zhaopin")

public class ZhishuZhaopinController extends MvcController {
//	private AbstractBaseService<ZhishuZhaopinFYB> zhaopin = ServiceBeanFactory.get(ZhishuZhaopinFYB.class, null);
	@Path({ "/fengyunbang" })
	@GET
	@POST
	public ActionResult fengyunbang() {
		
        HttpServletRequest request = beat.getRequest();	
		String city = MyServletRequestUtils.getStringParameter(request, "city", "");
		String cate = MyServletRequestUtils.getStringParameter(request, "cate", "");
		String months = MyServletRequestUtils.getStringParameter(request, "months", "");
		
		if(city==""|cate==""|months==""){
			//默认  一级城市：全国   ，二级类别：全部 ， 时间：1个月
			city = "全国";
			cate = "人事/行政/后勤";
			months = "1";
		}
		
		Map<String,Object> context = beat.getModel().getModel();
				
		Map<String,Object> zhaopin = ZhishuZhaopinBLL.getZhaopinJson(city, cate, months);
		//城市和类别
		context.put("CityList",ResumeConst.CityList);		
		context.put("CateList",ResumeConst.CateList);

		context.put("city",city);
		context.put("cate",cate);
		context.put("months",months);
		context.put("zhaopin",zhaopin);
		
		return ActionResult.view("zhishuzhaopin/fengyunbang");

	}
	
	
	@Path({ "/qushi" })
	@GET
	@POST
	public ActionResult qushi() {		
		Map<String,Object> context = beat.getModel().getModel();	
		//城市和类别
		Map<String,List<String>> map = ZhishuZhaopinBLL.getCityAndCate();
		context.put("CityList",map.get("cityList"));		
		context.put("CateList",map.get("cateList"));
		return ActionResult.view("zhishuzhaopin/qushi");

	}
	
	/**
	 *  职位排行榜
	 */
	@Path("/position")
	@POST
	@GET
	public ActionResult position(){
		 HttpServletRequest request = beat.getRequest();	
		 Model model = beat.getModel();
		 Map<String,String> map = new HashMap<String,String>();
		 String city = MyServletRequestUtils.getStringParameter(request, "city", "");
		 String year = MyServletRequestUtils.getStringParameter(request, "year", "年度榜单");
		 String season = MyServletRequestUtils.getStringParameter(request, "season", "季度榜单");
		 String month = MyServletRequestUtils.getStringParameter(request, "month", "月度榜单");
		 String clickId = MyServletRequestUtils.getStringParameter(request, "clickId", "month");
		 try{
			 
			
			if(!"季度榜单".equals(season)){
			 //季度排行榜	 
				
				 map.put("year", year);
				 map.put("season", season);
				 
			 }else if(!"年度榜单".equals(year)){
			 //年度排行榜
				 
				 map.put("year", year);
			 }else {
			    //初始化 
				//月排行榜
				 map.put("year", year);
				 month = "2016年8月";
			 }
			 
		 }catch(Exception e){
			 e.printStackTrace();
		 }
		 
		 JSONObject js = new JSONObject();
		 List<Integer> list = Lists.newArrayList(); 
		 list.add(2011);
		 list.add(8);
		 js.put("begin_date", list);
		 list.clear();
		 list.add(2016);
		 list.add(8);
		 js.put("end_date", list);
		 model.add("city",city);
		 model.add("year",year);
		 model.add("season",season);
		 model.add("month",month);
		 model.add("clickId",clickId);
		 model.add("date",js);
		return ActionResult.view("zhishuzhaopin/position");
		
	}
	
	/**
	 *  城市排行榜
	 */
	@Path("/city")
	@POST
	@GET
	public ActionResult city(){
		 HttpServletRequest request = beat.getRequest();
		 Model model = beat.getModel();
		 Map<String,String> map = new HashMap<String,String>();
		 String position = MyServletRequestUtils.getStringParameter(request, "position", "");		
		 String year = MyServletRequestUtils.getStringParameter(request, "year", "年度榜单");
		 String season = MyServletRequestUtils.getStringParameter(request, "season", "季度榜单");
		 String month = MyServletRequestUtils.getStringParameter(request, "month", "月度榜单");
		 String clickId = MyServletRequestUtils.getStringParameter(request, "clickId", "month");
		 try{
			 
			
			if(!"季度榜单".equals(season)){
			 //季度排行榜	 
				
				 map.put("year", year);
				 map.put("season", season);
				 
			 }else if(!"年度榜单".equals(year)){
			 //年度排行榜
				 
				 map.put("year", year);
			 }else {
			    //初始化 
				//月排行榜
				 map.put("year", year);
				 month = "2016年8月";
			 }
			 
		 }catch(Exception e){
			 e.printStackTrace();
		 }
		 JSONObject js = new JSONObject();
		 List<Integer> list = Lists.newArrayList(); 
		 list.add(2012);
		 list.add(8);
		 js.put("begin_date", list);
		 list.clear();
		 list.add(2016);
		 list.add(07);
		 js.put("end_date", list);
		 model.add("position",position);
		 model.add("year",year);
		 model.add("season",season);
		 model.add("clickId",clickId);
		 model.add("month",month);
		 model.add("date",js);
		return ActionResult.view("zhishuzhaopin/city");		
	}
	
}
